package com.example.demo.demoApi.header;

import com.example.demo.typeEnums.APIResult;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*;

import java.io.Serializable;

/**
 * 响应头
 */
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class ResponseHeader implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 对应{@link RequestHeader}中的#requestId字段
     **/
    private String responseId;
    /**
     * 响应码
     */
    private int code;
    /**
     * 响应提示
     */
    private String msg;

    /**
     * i18n消息的参数列表（RMS内部字段）
     * @since 3.1.0
     */
    @JsonIgnore
    private Object[] args;

    /**
     * 透传字段（以原样返回用户传输的数据）
     * @since 3.1.0
     */
    private String ext;


    /**
     * 消息体
     *
     * @param result
     * @param args
     */
    public void setResponseHeader(APIResult result, Object... args) {
        this.code = result.getCode();
        this.msg = result.getMsg();
        this.args = args;
    }
}

